package org.springframework.beans.factory.support;

import com.google.common.base.Preconditions;
import lombok.Data;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanDefinition;

import java.util.*;

import static com.google.common.base.Preconditions.checkNotNull;

@Data
public class DefaultListableBeanFactory
        implements BeanDefinitionRegistry {
    private final Map<String, BeanDefinition> beanDefinitionMap = Collections.synchronizedMap(new LinkedHashMap<>(256));
    private volatile List<String> beanDefinitionNames = new ArrayList<>(256);
    private Map<String, BeanDefinition> bootstrapBeanDefinitionMap = Collections.synchronizedMap(new LinkedHashMap<>(256));

    @Override
    public void registerBootstrapBeanDefinition(String beanName,
                                                BeanDefinition beanDefinition) throws BeanDefinitionStoreException {
        bootstrapBeanDefinitionMap.put(beanName, beanDefinition);
        registerBeanDefinition(beanName, beanDefinition);
    }

    public void registerBeanDefinition(String beanName,
                                       BeanDefinition beanDefinition) throws BeanDefinitionStoreException {
        Preconditions.checkNotNull(beanName, "beanName must not be empty");
        Preconditions.checkNotNull(beanDefinition, "beanDefinition must not be empty");

        this.beanDefinitionMap.put(beanName, beanDefinition);
        this.beanDefinitionNames.add(beanName);
    }

    @Override
    public BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException {
        return null;
    }
}
